cmake_minimum_required(VERSION 3.3)

project(myMuduo)

set(CMAKE_CXX_STANDARD 11)

add_subdirectory(myMuduo/base)
add_subdirectory(myMuduo/net)
add_subdirectory(myMuduo/database)

set(CMAKE_CXX_FLAGS -pthread)

set(mymuduo base net database)
set(otherlib libyaml-cpp.a)

add_executable(AysncLogHttpServerTest
        myMuduo/test/AsyncLogHttpServerTest.cpp)
target_link_libraries(AysncLogHttpServerTest
        ${mymuduo}
        ${otherlib})

add_executable(HttpServletTest
        myMuduo/test/HttpServletTest.cpp)
target_link_libraries(HttpServletTest
        ${mymuduo}
        ${otherlib})

add_executable(MyTest myMuduo/test/MyTest.cpp)

#add_executable(test myMuduo/test/MyTest.cpp)
# target_link_libraries(test libyaml-cpp.a)
#[=[导入库]=]

set(INC_DIR /www/server/mysql/include /usr/local/include) #声明头文件路径，安装mysql的include文件夹，文件路径中有空格的地方，在空格前加上转义\

set(LINK_DIR /www/server/mysql/bin /usr/local/lib64) #声明链接库路径，安装mysql的lib文件夹，

include_directories(${INC_DIR}) #引入头文件

link_directories(${LINK_DIR}) #引入库文件

# 下面的暂时可以无视了
#[[线程导入]]
#[[set(CMAKE_CXX_FLAGS -pthread)

#[=[基本头文件]=]
set(base_head
        myMuduo/base/Timestamp.h
        myMuduo/base/FileUtils.h
        myMuduo/base/log/LogStream.h
        myMuduo/base/log/Logging.h
        myMuduo/base/log/LogFile.h
        myMuduo/base/log/AsyncLogging.h
        myMuduo/base/copy/noncopyable.h
        myMuduo/base/copy/copyable.h
        myMuduo/base/Atomic.h
        myMuduo/base/Types.h
        myMuduo/base/thread/CountDownLatch.h
        myMuduo/base/thread/CurrentThread.h
        myMuduo/base/thread/Mutex.h
        myMuduo/base/thread/Thread.h
        myMuduo/base/thread/ThreadPool.h
        myMuduo/base/json/JsonUtils.h
        myMuduo/base/Endian.h
        myMuduo/base/ByteArray.h
        )

#[=[基本头文件实现类]=]
set(base_member
        myMuduo/base/thread/Mutex.cpp
        myMuduo/base/Timestamp.cpp
        myMuduo/base/FileUtils.cpp
        myMuduo/base/log/LogStream.cpp
        myMuduo/base/log/Logging.cpp
        myMuduo/base/log/LogFile.cpp
        myMuduo/base/log/AsyncLogging.cpp
        myMuduo/base/thread/CountDownLatch.cpp
        myMuduo/base/thread/CurrentThread.cpp
        myMuduo/base/thread/Thread.cpp
        myMuduo/base/thread/ThreadPool.cpp
        myMuduo/base/json/JsonUtils.cpp
        myMuduo/base/ByteArray.cpp
        )

#[=[网络相关头文件]=]
set(tcp_head
        myMuduo/net/tcp/Channel.h
        myMuduo/net/reactor/EventLoop.h
        myMuduo/net/reactor/TimerId.h
        myMuduo/net/reactor/Timer.h
        myMuduo/net/reactor/TimerQueue.h
        myMuduo/net/Buffer.h
        myMuduo/net/reactor/Poller.h
        myMuduo/net/poller/PollPoller.h
        myMuduo/net/poller/EPollPoller.h
        myMuduo/net/reactor/EventLoopThread.h
        myMuduo/net/reactor/EventLoopThreadPool.h
        myMuduo/net/tcp/InetAddress.h
        myMuduo/net/tcp/SocketUtils.h
        myMuduo/net/tcp/Socket.h
        myMuduo/net/tcp/Acceptor.h
        myMuduo/net/reactor/Callback.h
        myMuduo/net/TcpConnection.h
        myMuduo/net/TcpServer.h
        myMuduo/net/Connector.h
        )

#[=[网络相关成员]=]
set(tcp_member
        myMuduo/net/tcp/Channel.cpp
        myMuduo/net/reactor/EventLoop.cpp
        myMuduo/net/reactor/Timer.cpp
        myMuduo/net/reactor/TimerQueue.cpp
        myMuduo/net/Buffer.cpp
        myMuduo/net/reactor/Poller.cpp
        myMuduo/net/poller/PollPoller.cpp
        myMuduo/net/poller/EPollPoller.cpp
        myMuduo/net/poller/DefaultPoller.cpp
        myMuduo/net/reactor/EventLoopThread.cpp
        myMuduo/net/reactor/EventLoopThreadPool.cpp
        myMuduo/net/tcp/InetAddress.cpp
        myMuduo/net/tcp/SocketUtils.cpp
        myMuduo/net/tcp/Socket.cpp
        myMuduo/net/tcp/Acceptor.cpp
        myMuduo/net/TcpConnection.cpp
        myMuduo/net/TcpServer.cpp
        myMuduo/net/Connector.cpp
        )

#[=[http相关头文件]=]
set(tcp_http_head
        myMuduo/net/http/HttpRequest.h
        myMuduo/net/http/HttpContext.h
        myMuduo/net/http/HttpResponse.h
        myMuduo/net/http/HttpServer.h
        )

#[=[http相关成员实现]=]
set(tcp_http_member
        myMuduo/net/http/HttpContext.cpp
        myMuduo/net/http/HttpResponse.cpp
        myMuduo/net/http/HttpServer.cpp
        )

set(my_muduo
        ${base_head}
        ${tcp_head}
        ${base_member}
        ${tcp_member}
        ${tcp_http_head}
        ${tcp_http_member}
        myMuduo/net/html/htmlConstant.h
        )

set(test_member
        myMuduo/net/json/JsonObject.h
        myMuduo/net/json/JsonUtils.h
        myMuduo/net/json/JsonObject.cpp
        myMuduo/net/json/JsonUtils.cpp
        )

set(database_head
        myMuduo/database/mysql/MySQLConnection.h
        myMuduo/database/mysql/ConnectionPool.h
        )

set(database_member
        myMuduo/database/mysql/MySQLConnection.cpp
        myMuduo/database/mysql/ConnectionPool.cpp )

#[=[下面是测试文件]=]

add_executable(ServerTest
        ${my_muduo}
        myMuduo/test/ServerTest.cpp
        )

add_executable(ClientTest
        ${my_muduo}
        myMuduo/test/ClientTest.cpp
        )

add_executable(HttpServerTest
        ${my_muduo}
        myMuduo/test/HttpServerTest.cpp)

add_executable(AysncLogHttpServerTest
        ${my_muduo}
        ${database_head}
        ${database_member}
        myMuduo/test/AsyncLogHttpServerTest.cpp)

add_executable(Test myMuduo/test/BaseTest.cpp)

add_executable(JsonTest
        myMuduo/test/JsonTest.cpp)

add_executable(MyTest myMuduo/test/MyTest.cpp)

add_executable(MySqlConnectionTest
        ${base_head}
        ${base_member}
        ${database_head}
        ${database_member}
        myMuduo/test/MySqlConnectionTest.cpp)

add_executable(TimerQueueTest
        ${my_muduo}
        myMuduo/test/TimerQueueTest.cpp)

#[=[导入库]=]

set(INC_DIR /www/server/mysql/include ) #声明头文件路径，安装mysql的include文件夹，文件路径中有空格的地方，在空格前加上转义\

set(LINK_DIR /www/server/mysql/bin /usr/local/lib64) #声明链接库路径，安装mysql的lib文件夹，

include_directories(${INC_DIR}) #引入头文件

link_directories(${LINK_DIR}) #引入库文件
link_libraries(libmysqlclient.so libjsoncpp.a)
target_link_libraries(MySqlConnectionTest libmysqlclient.so)
target_link_libraries(AysncLogHttpServerTest libmysqlclient.so)
target_link_libraries(MyTest libjsoncpp.a)
target_link_libraries(JsonTest libjsoncpp.a)
# 注意这里引入的是libmysqlclient.so这个库, 这个库文件必须要保证存在于/usr/lib中才能成功运行]]

